<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    class Company_news_model extends MY_Model
    {        
    	public function __construct() 
        {
            parent::__construct();
            $this->tbl_name = 'news';
        }
        
        public function getNewById($id)
        {
            $sql = "SELECT *
                    FROM news 
                    WHERE active = 1 AND id=".$id;
            $query = $this->db->query($sql);

            if ($query->num_rows() > 0)
            {
               $row = $query->row_array();
               return $row;
            }
        }
        
        public function getOtherNewForSameCompany($news_id,$company_id)
        {
            $sql = "SELECT *
                    FROM news 
                    WHERE id != $news_id AND companies_id = $company_id AND active = 1
                    ORDER BY id DESC
                    LIMIT 10";
            
            $query = $this->db->query($sql);

            $data = array();
            if ($query->num_rows() > 0)
            {
               foreach ($query->result_array() as $row)
               {
                    $data[] = $row;    
               }
               return $data;
            }   
        }
        
        public function getNewCompanyId($id)
        {
            $sql = "SELECT *
                    FROM news 
                    WHERE active = 1 
                    AND companies_id = $id
                    ORDER BY id DESC
                    LIMIT 1";
            $query = $this->db->query($sql);

            if ($query->num_rows() > 0)
            {
               $row = $query->row_array();
               return $row;
            }
        }
        
        public function getAllNews()
        {
            $sql = "SELECT *
                    FROM news 
                    WHERE active = 1 AND new_types_id = 5
                    ORDER BY id DESC
                    LIMIT 7";
            
            $query = $this->db->query($sql);

            $data = array();
            if ($query->num_rows() > 0)
            {
               foreach ($query->result_array() as $row)
               {
                    $data[] = $row;    
               }
               return $data;
            } 
        }
        
        public function getMarketNews()
        {
            $sql = "SELECT *
                    FROM news 
                    WHERE active = 1 AND new_types_id = 4
                    ORDER BY id DESC
                    LIMIT 5";
            
            $query = $this->db->query($sql);

            $data = array();
            if ($query->num_rows() > 0)
            {
               foreach ($query->result_array() as $row)
               {
                    $data[] = $row;    
               }
               return $data;
            } 
        }
    }
?>
